--=========================
--=	Colonies: Redeux 
--=	
--=========================
AddCSLuaFile("coloniesclient.lua")

	 
	coloniesnames = {
		"Bob",
		"Frank",
		"John",
		"David",
		"Mark",
		"Carl",
		"Russell",
		"Neil",
		"Amy",
		"Chris",
		"Aimiee",
		"Sarah",
		"Kent",
		"Barry",
		"Scott",
		"Christene",
		"Jenny",
		"Josh",
		"Alyx",
		"Gordon",
		"Eli",
		"Isaac",
		"Wallace"
	}

	headcrabgenes = {
		"Mercury", //Extra speed
		"Brute", //More health
		"Tank", //Just much higher health
		"Spartan", //Never flees
		"Unyielding", //Takes more damage before fleeing
		"Pusillanimous", //Takes less damage before fleeing
		"Voracious", //Gets hungry more quickly
		"Fangs", //Greater damage
		"Efficient", //Less hunger
		"Strong", //Relatively high health and damage
		"Survivor", //High hunger threshold
		"Hotwire", //Fast reaction times
		"Slowpoke", //Slow reaction times
		"Mother", //High fertility rate
		"Witch", //Passive at first, but can become enraged
		"Hyperactive", //More prone to wandering
		"Elephant", //Greater lifespan
		"Mayfly", //Short lifespan
		"Explorer", //Wanders further, more prone to journeys
		"Panacea", //Fast healing rate
		"Asbestos" //Fire resistant
	}

--Global things
CreateConVar("co_printevents",1, {FCVAR_NOTIFY}) --Wether or not to print info on deaths
CreateConVar("co_spreadthelove",0, {FCVAR_NOTIFY}) --If 1, Headcrabs and Antlions won't hate eachother.

--Watermelon stuff
CreateConVar("co_watermelon_time",30, {FCVAR_NOTIFY}) --Time between each new watermelon
CreateConVar("co_watermelon_distance",20, {FCVAR_NOTIFY}) --Maximum/Minimum distance watermelons can spawn from the plant
CreateConVar("co_watermelon_max",60, {FCVAR_NOTIFY}) --Maximum number of watermelons before plant stops spawning

--Headcrab Vars
CreateConVar("co_headcrab_lifespan",200, {FCVAR_NOTIFY}) --How long the headcrab lives for
CreateConVar("co_headcrab_hunger",1, {FCVAR_NOTIFY}) -- How quickly the hunger increases
CreateConVar("co_headcrab_searchrad",4096, {FCVAR_NOTIFY}) -- Radius to search for food
CreateConVar("co_headcrab_eggtime",10, {FCVAR_NOTIFY}) --How long before egg hatches
CreateConVar("co_headcrab_maturetime",20, {FCVAR_NOTIFY}) --How long before the Headcrab matures
CreateConVar("co_headcrab_pregtime",50, {FCVAR_NOTIFY}) --How long between each egg
CreateConVar("co_headcrab_max",30, {FCVAR_NOTIFY}) --Maximum headcrab population
CreateConVar("co_headcrab_hateplayers",0, {FCVAR_NOTIFY}) --Maximum headcrab population
CreateConVar("co_headcrab_tozombie",0, {FCVAR_NOTIFY}) --Should Headcrabs spawn zombies when they kill citizens
CreateConVar("co_headcrab_cuddlyzombie",0, {FCVAR_NOTIFY}) --Zombies hate players?

--Antlion Vars
CreateConVar("co_antlion_lifespan",320, {FCVAR_NOTIFY}) 
CreateConVar("co_antlion_hunger",1, {FCVAR_NOTIFY})
CreateConVar("co_antlion_searchrad",4096, {FCVAR_NOTIFY}) -- Radius to search for food
CreateConVar("co_antlion_eggtime",10, {FCVAR_NOTIFY})
CreateConVar("co_antlion_maturetime",20, {FCVAR_NOTIFY})
CreateConVar("co_antlion_pregtime",60, {FCVAR_NOTIFY})
CreateConVar("co_antlion_max",30, {FCVAR_NOTIFY}) --Maximum antlion population
CreateConVar("co_antlion_hateplayers",0, {FCVAR_NOTIFY}) --Makes antlions hate persons

hook.Add("Initialize","ColonyTags",function() local tags = GetConVarString("sv_tags") or ""
	RunConsoleCommand("sv_tags", tags..",colonies") 
end)

hook.Add("OnNPCKilled","ColonyKilledNPC",function(v, k, w) 
	
	if v:GetClass() == "npc_headcrab" or v:GetClass() == "npc_antlion" then
		local ragdoll = ents.Create("prop_ragdoll")
		if v:GetClass() == "npc_headcrab" then
		ragdoll:SetModel("models/headcrabclassic.mdl")
		elseif v:GetClass() == "npc_antlion" then
		ragdoll:SetModel("models/antlion.mdl")
		end
		ragdoll:SetPos(v:GetPos()+Vector(0,0,1))
		ragdoll:SetAngles(v:GetAngles())
		ragdoll:SetCollisionGroup(COLLISION_GROUP_DEBRIS)

		//if undo.ReplaceEntity(self.Entity,ragdoll) then PrintMessage(HUD_PRINTTALK,"Corpse.") end
		ragdoll:Spawn()
		v:Remove()

			timer.Create("Delete Ragdoll Delay ", 2, 1, function()
    			timer.Create("Delete Ragdoll ", 0.02, 256, function()  
      
       				local r,g,b,a = ragdoll:GetColor()  
        			if a <= 0 then  
        				ragdoll:Remove()
					PrintMessage(HUD_PRINTTALK,"Removed.")
        			else  
					Alpha1 = math.Approach(a, 0, 1)  
					ragdoll:SetColor(r, g, b, Alpha1)  
       				end       
   			end)
			end)

	end
		
	
	if k:GetClass():sub(1,12) == "npc_headcrab" and ( v:GetClass() == "npc_citizen" ) and k:GetNWBool("HC") and GetConVarNumber("co_headcrab_tozombie") == 1 then
		--Remove both the headcrab and the killed NPC and replace with zombie
		local zombietype = "npc_zombie"
		if k:GetClass() == "npc_headcrab_fast" then
			zombietype = "npc_fastzombie"
		elseif k:GetClass() == "npc_headcrab_black" then
			zombietype = "npc_poisonzombie"
		end
		local zomb = ents.Create(zombietype)
		zomb:SetPos(v:GetPos())
		zomb:Spawn()
		if GetConVarNumber("co_headcrab_cuddlyzombie") == 1 then
			zomb:AddRelationship("player D_NU 999")
		end
		v:Remove()
		k:Remove()
	end
	
end)

/*
hook.Add("OnTakeDamage","Entitytakedamage", EntityTakeDamage( ent, inflictor, attacker, amount, dmginfo )

if attacker:GetClass() == "npc_antlion" then
if ent:GetClass()
*/
